﻿using Entity.BaseInfo.DTO.Customer;
using Entity.BaseInfo.View.Customer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.BaseInfo;

namespace AnQinManagermentBackendAPI.Controller.BaseInfo
{
    /// <summary>
    /// 客户表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class CustomerController : ControllerBase
    {
        /**
         * 客户业务接口
         */
        private readonly CustomerService _customerService;

        /**
         * 构造函数注入
         */
        public CustomerController(CustomerService customerService)
        {
            _customerService = customerService;
        }

        /// <summary>
        /// 获取客户列表
        /// </summary>
        /// <param name="customerSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(CustomerView), 200)]
        public async Task<IActionResult> GetCustomerList([FromQuery] CustomerSearchDTO customerSearchDTO)
        {
            var response = await _customerService.GetCustomerList(customerSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增客户
        /// </summary>
        /// <param name="customerAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddCustomer([FromBody] CustomerAddDTO customerAddDTO)
        {
            var response = await _customerService.AddCustomer(customerAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新客户
        /// </summary>
        /// <param name="customerUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutCustomer([FromBody] CustomerUpdateDTO customerUpdateDTO)
        {
            var response = await _customerService.PutCustomer(customerUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除客户
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteCustomer([FromQuery] string Id)
        {
            var response = await _customerService.DeleteCustomer(Id);
            return StatusCode(response.Status, response);
        }
    }
}
